let request = {
	url,
	method,
	data,
	header
} => {
	return new Promise((resolve, reject) => {
		if (!headers) {
			const token = uni.getStorageSync('token');
			header = {
				'Content-Type': 'application/json;charset=utf-8',
				Authorization: token
			}
		}
		uni.request({
			url: process.env.config[process.env.NAME].requestBaseUrl + url,
			data,
			method,
			header,
			success(res) {
				const {
					code,
					msg,
					data
				} = res.data;
				if (code == 200) return resolve(data);

				uni.showToast({
					icon: "none",
					duration: 3000,
					title: msg
				})
				return reject(msg);
			},
			fail(error) {
				console.log("请求错误:", error);
				uni.showToast({
					icon: "none",
					duration: 3000,
					title: "网络异常,请稍后重试!"
				})
				return reject(error);
			},
			complete() {
				// 成功失败都调用
			}
		})
	})
}

export const get = (url = '', data) => request({
	url,
	method: "GET",
	data,
})

export const post = (url = '', data) => request({
	url,
	method: "POST",
	data,
})

export const put = (url = '', data) => request({
	url,
	method: "PUT",
	data,
})

export const delete = (url = '', data) => request({
	url,
	method: "DELETE",
	data,
})